---
title: Run the OnBase keyword sync
summary: The application's single Execute-stage operation that clears invalid records, retrieves unprocessed keyword syncs, and syncs them to OnBase.
status: draft
owner: Documents
last_reviewed: 2026-09-17
operation_id: OP-001
trigger: ConsoleBase.Run() after Initialize() returns and Environment.ExitCode is set to 0
---

# OP-001: Run the OnBase keyword sync

This is the entire business operation of the application. It logs the run mode, clears invalid person keyword syncs, retrieves and orders the unprocessed batch, delegates the sync to OnBase, and rethrows any exception so the framework can map it to an exit code.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-001 |
| **Trigger** | `ConsoleBase.Run()` after `Initialize()` returns and `Environment.ExitCode` is set to `0`† |
| **Lifecycle stage** | Execute |
| **Owning component** | `OnBaseKeywordSyncRunner.Execute` |
| **Inputs** | None from the command line; all inputs are environment settings and Imaging API data |
| **Outputs** | OnBase keyword updates applied; Imaging API records marked processed; narrated console/log output |
| **Failure exit code** | `5` — any unhandled exception rethrown from `Execute()` |

## Steps

1. Log `"OnBase Keyword Sync execution started."`
2. Read `OnBaseKeywordSync.onbaseasync` as `bool` and log the resulting mode ([BR-OBKS-001](../business-rules.md#br-obks-001-asynchronous-or-synchronous-update-mode))
   - On failure: a `bool` conversion failure throws an exception → exit code `5`
3. Construct `ImagingApiClient`: read `imagingapiurl`, append `v1/Integration`, read `onbasekeywordsync.imagingClientTimeoutSeconds`, and build a `JsonHttpClient` with `ClientInfo { ApplicationId = "OnBaseKeywordSync", MachineName = <machine, upper>, UserId = <Windows user, upper> }` and a timeout in milliseconds
   - On failure: a missing/invalid setting throws an exception → exit code `5`
4. Delegate to [OP-002](clear-invalid-person-keyword-syncs.md) (clear invalid person keyword syncs) ([BR-OBKS-002](../business-rules.md#br-obks-002-invalid-person-keyword-syncs-cleared-before-the-batch))
   - On failure: propagates → exit code `5`
5. `GET ImageKeywordSyncs?getDocumentCount={OnBaseKeywordSync.getdocumentcount}`, order the result by `Id` ascending ([BR-OBKS-003](../business-rules.md#br-obks-003-unprocessed-records-processed-in-ascending-id-order))
   - On failure: propagates → exit code `5`
6. Log the record count and the sum of `TotalDocumentUpdates`
   - On failure: `KeywordUpdates` null on any record throws `NullReferenceException` → exit code `5`*
7. Delegate to [OP-003](sync-a-keyword-batch-with-onbase.md) (sync the batch with OnBase) ([BR-OBKS-004](../business-rules.md#br-obks-004-document-count-gates-whether-a-record-is-sent), [BR-OBKS-005](../business-rules.md#br-obks-005-equal-prior-and-new-values-are-not-sent), [BR-OBKS-006](../business-rules.md#br-obks-006-trigger-type-and-query-keyword-derived-by-precedence), [BR-OBKS-007](../business-rules.md#br-obks-007-empty-new-value-applied-as-keyword-deletion), [BR-OBKS-008](../business-rules.md#br-obks-008-custom-query-selected-from-doc-type-group-mapping), [BR-OBKS-009](../business-rules.md#br-obks-009-flag-keyword-translation))
   - On failure: propagates → exit code `5`
8. On any exception: `LogError` the message, `LogException` the exception, rethrow
   - The framework maps the rethrown exception to exit code `5`†

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
    A["Log execution started"] --> B["Read onbaseasync<br>and log the mode"]
    B --> C["Construct ImagingApiClient"]
    C --> D["OP-002: Clear invalid<br>person keyword syncs"]
    D --> E["Retrieve unprocessed<br>keyword syncs, order by Id"]
    E --> F["Log record count<br>and total document updates"]
    F --> G["OP-003: Sync a keyword<br>batch with OnBase"]
    G --> H["Complete"]
    B -.->|Conversion failure| ERR["Exit code 5"]
    C -.->|Missing setting| ERR
    D -.->|Exception| ERR
    E -.->|Exception| ERR
    F -.->|NullReferenceException| ERR
    G -.->|Exception| ERR
```

## Logging

| Log id | Written content |
| --- | --- |
| Not application-assigned (fans out to all registered `file0`–`file4` writers) | `"OnBase Keyword Sync execution started."`, `"Updates will be sent to OnBase {asynchronously\|synchronously}"`, `"Found {n} unprocessed image_keyword_sync records with a total of {m} total docs to update."` |

## Error handling
- Any exception raised during this operation is logged (`WriteError` + `LogException`) and rethrown; `ProgramRunnerBase` maps the rethrown exception to exit code `5`, since no `SaifConsoleException` subclass is ever thrown by this application.
- There is no per-record error isolation: one failed record aborts the remaining batch, and already-processed records are not rolled back*.

## Related documentation
- [Run lifecycle](../run-lifecycle.md)
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Operational runbook](../operational-runbook.md)

> **Note:** Statements marked with `†` are derived from dependency library documentation via the Legends CLI. Statements marked with `*` were inferred from code structure or contextual evidence.

## Sources
- `OnBaseKeywordSync/OnBaseKeywordSyncRunner.cs`
- `OnBaseKeywordSync/Services/ImagingApiClient.cs`
